/*
 * vue配置文件
 * created by Jing
 */

// vue过滤器
Vue.filter('date', function(val){
    var operateDate = new Date(val),
        year = operateDate.getFullYear(),
        month = operateDate.getMonth() + 1,
        day = operateDate.getDate();
        
    month = month > 9 ? month : "0" + month.toString();
    day = day > 9 ? day : "0" + day.toString();
    
    return year + "/" + month + "/" + day;
});

Vue.filter('prefix', function(val){
	if(typeof val != 'string'){
		return val;
	}
    var res = 0,
        len = val.length,
        prefix = "";
    if(val.indexOf("/uimg/") >= 0){
		for(var i = 0; i < len; i++){
            res = res * 31 + val.charCodeAt(i);
        }
        prefix = Autophoto.staticImg.replace("?", res % 5 == 0 ? "" : res % 5);
        console.log(prefix)
        return prefix + val;
    }else{
        return val;
    }
});

// 组件
Vue.component("err-rule", {
    props: ["err", "errCtt"],
    template: '<section class="popup" v-show="err"><div class="popup-bg"><div class="popup-ctt">{{errCtt}}</div></div></section>',
});

//球队标志
Vue.filter('mark', function(val){
	var markList = ["广州恒大淘宝","上海上港","山东鲁能泰山","北京国安乐视","河南建业","上海绿地申花","石家庄永昌","重庆力帆","江苏苏宁","长春亚泰","杭州绿城","辽宁宏运","天津泰达","广州富力","延边富德","河北华夏幸福"],
		markIcon = markList.indexOf(val);
	function pad(num, n) {  
    	var len = num.toString().length;  
	    while(len < n) {  
	        num = "0" + num;  
	        len++;  
	    }  
	    return num;  
	}
	if(markIcon!="-1"){
    	return "<img src=\"img/mark/mark_"+ pad(markIcon,2) +".png\" />";
    }
});

Vue.filter('state', function(val){
    if(val=="1"){
    	return "未领取";
    }else if(val=="2"){
    	return "已领取";
    }else{
    	return "部分领取";
    }
});

Vue.filter('print', function(val){
    if(val=="Y"){
    	return "已取票";
    }else{
    	return "未取票";
    }
});